<template>
  <div id="app" class="iphonex">
    <transition :name="transitionName">
      <router-view class="Router" />
    </transition>
  </div>
</template>
<script>
export default {
  data() {
    return {
      transitionName: 'slide-right' //初始过渡动画方向
    }
  },
  watch: {
    $route(to, from) {
      // 切换动画
      let toName = to.name
      console.log(toName)
      const toIndex = to.meta.index
      const fromIndex = from.meta.index
      this.transitionName = toIndex > fromIndex ? 'slide-right' : 'slide-left'
    }
  }
}
</script>
<style lang="less">
@import './assets/base.less';
@import './assets/comm.less';

#app {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #333;
  height: 100%;
  position: relative;
  text-align: center;
  //配置过渡动画
  .Router {
    position: absolute;
    height: 100%;
    transition: all 0.377s ease;
    will-change: transform;
    top: 0;
    backface-visibility: hidden;
    perspective: 1000;
  }

  .slide-left-enter,
  .slide-right-leave-active {
    opacity: 0;
    transform: translate3d(-100%, 0, 0);
  }

  .slide-left-leave-active,
  .slide-right-enter {
    opacity: 0;
    transform: translate3d(100%, 0, 0);
  }
}
</style>

